package com.model.defaults.actionbar.entities;

import java.util.Map;

import org.hibernate.Session;

import com.core.utils.GlobalConstants;
import com.model.ActionBarItem;
import com.model.ActionScript;
import com.model.KeyValue;
import com.model.UserContextName;


public class ModelDefaultActionbarItemsTeamMember {

	public static void createActionBarItems ( Session session,
	                                          Map <String, UserContextName> userContexts ) {

		ModelDefaultActionbarItemsTeamMember.createActionBarItemsUserInfo(session, userContexts);

		ModelDefaultActionbarItemsTeamMember.createActionBarItemsUserAdd(session, userContexts);

		ModelDefaultActionbarItemsTeamMember.createActionBarItemsUserUpdate(session, userContexts);

		ModelDefaultActionbarItemsTeamMember.createActionBarItemsProjectMember(session, userContexts);
	}



	private static void createActionBarItemsProjectMember ( Session session,
	                                                        Map <String, UserContextName> userContexts ) {

		UserContextName visibleInContextName_1 = null;
		ActionBarItem pojo = null;

		KeyValue actionScriptParam = new KeyValue("p1", "?");
		actionScriptParam.setUserInfo(GlobalConstants.ACTIONSCRIPT_USERINFO_PARAM_KEY);
		session.save(actionScriptParam);

		ActionScript actionScript = new ActionScript();
		actionScript.setActionScriptText("%s?{p1}", GlobalConstants.SERVLET_TEAMMEMBERADD);
		actionScript.setActionScriptType("servlet");
		actionScript.getParams().add(actionScriptParam);
		session.save(actionScript);

		visibleInContextName_1 = userContexts.get(GlobalConstants.USERCONTEXT_TEAMMEMBERLIST);
		UserContextName userContextNameToExecute = userContexts.get(GlobalConstants.USERCONTEXT_TEAMMEMBERADD);
		pojo = new ActionBarItem();
		pojo.setName("actionbar.taskitem.addtask");
		pojo.getUserContextNameVisibleIn().add(visibleInContextName_1);
		pojo.setUserContextNameToExecute(userContextNameToExecute);
		pojo.setActionScript(actionScript);
		session.save(pojo);
	}



	private static void createActionBarItemsUserInfo ( Session session,
	                                                   Map <String, UserContextName> userContexts ) {

		UserContextName visibleInContextName_1 = null;
		ActionBarItem pojo = null;

		KeyValue actionScriptParam = new KeyValue("p3", "?");
		actionScriptParam.setUserInfo(GlobalConstants.ACTIONSCRIPT_USERINFO_PARAM_KEY);
		session.save(actionScriptParam);

		ActionScript actionScript = new ActionScript();
		actionScript.setActionScriptType("servlet");
		actionScript.setActionScriptText("%s?{p3}", GlobalConstants.SERVLET_TEAMMEMBERUPDATE);
		actionScript.getParams().add(actionScriptParam);
		session.save(actionScript);

		visibleInContextName_1 = userContexts.get(GlobalConstants.USERCONTEXT_TEAMMEMBERINFO);
		UserContextName userContextNameToExecute = userContexts.get(GlobalConstants.USERCONTEXT_TEAMMEMBERUPDATE);
		pojo = new ActionBarItem();
		pojo.setName("actionbar.teammember.edit");
		pojo.getUserContextNameVisibleIn().add(visibleInContextName_1);
		pojo.setUserContextNameToExecute(userContextNameToExecute);
		pojo.setActionScript(actionScript);
		session.save(pojo);
	}



	private static void createActionBarItemsUserAdd ( Session session,
	                                                  Map <String, UserContextName> userContexts ) {

		UserContextName visibleInContextName_1 = null;
		ActionBarItem pojo = null;
		visibleInContextName_1 = userContexts.get(GlobalConstants.USERCONTEXT_TEAMMEMBERADD);
		UserContextName userContextNameToExecute = userContexts.get(GlobalConstants.USERCONTEXT_TEAMMEMBERADD);

		KeyValue actionScriptParam = new KeyValue("form", "?");
		session.save(actionScriptParam);

		ActionScript actionScript = new ActionScript();
		actionScript.setActionScriptType("javascript");
		actionScript.setActionScriptText("javascript:document.{form}.submit();");
		actionScript.getParams().add(actionScriptParam);
		session.save(actionScript);

		pojo = new ActionBarItem();
		pojo.setName("actionbar.taskitem.addtask");
		pojo.getUserContextNameVisibleIn().add(visibleInContextName_1);
		pojo.setUserContextNameToExecute(userContextNameToExecute);
		pojo.setActionScript(actionScript);
		session.save(pojo);

	}



	private static void createActionBarItemsUserUpdate ( Session session,
	                                                     Map <String, UserContextName> userContexts ) {

		UserContextName visibleInContextName_1 = null;
		ActionBarItem pojo = null;
		ActionScript actionScript = null;
		KeyValue actionScriptParam = null;
		visibleInContextName_1 = userContexts.get(GlobalConstants.USERCONTEXT_TEAMMEMBERUPDATE);
		UserContextName userContextNameToExecute = userContexts.get(GlobalConstants.USERCONTEXT_TEAMMEMBERUPDATE);

		actionScriptParam = new KeyValue("form", "?");
		session.save(actionScriptParam);

		actionScript = new ActionScript();
		actionScript.setActionScriptType("javascript");
		actionScript.setActionScriptText("javascript:document.{form}.submit();");
		actionScript.getParams().add(actionScriptParam);
		session.save(actionScript);

		pojo = new ActionBarItem();
		pojo.setName("actionbar.teammember.update");
		pojo.getUserContextNameVisibleIn().add(visibleInContextName_1);
		pojo.setUserContextNameToExecute(userContextNameToExecute);
		pojo.setActionScript(actionScript);
		session.save(pojo);


	}

}
